package com.mtx.weatherreport.bean;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.mtx.weatherreport.Constant.SomeConstant;

/**
 * @author yinghuayu
 * @create 2018/2/26.
 */

public class NetUtil {

    public static int getNetworkState(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager)context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if(networkInfo == null) {
            return SomeConstant.NETWORK_NONE;  // 无网络连接
        }

        int nType = networkInfo.getType();
        if(nType == ConnectivityManager.TYPE_MOBILE) {
            return SomeConstant.NETWORK_MOBILE;  // 移动网络
        }else if(nType == ConnectivityManager.TYPE_WIFI) {
            return SomeConstant.NETWORK_WIFI;  // WIFI连接
        }

        return SomeConstant.NETWORK_NONE;
    }
}
